

import javax.swing.*;
import java.awt.*;
//import java.awt.event.*;

public class SudokuApplet extends JApplet {
    /**
     *
     */
	private static final long serialVersionUID = 1L;
	private Board board;
	private Solver solver;
	private View v;
	ControlPanel cp;
	
	public void init() {
	    setBackground( Color.white );
	    //String puzdir = "C:\\EclipseWork\\glasserr\\workspace\\Sudoku\\puzzles";
	    //String puzdir = "e:\\javaprogs\\Sudoku\\puzzles";
	    //String path = puzdir+"\\puzzle3.txt";  //getParameter("path");//
	    getContentPane().setLayout(new BorderLayout());
	    v = new View();
	    getContentPane().add(v, BorderLayout.CENTER);
	    cp = new ControlPanel(this);
	    getContentPane().add(cp, BorderLayout.EAST);
	    
    	solver = new Solver(v, board, this);
    	solver.updateBoardDef();
        v.setSolver(solver);
	}

	public void solve() {
	    if (!solver.isStarted()) {
	    	solver.start();
	    }
	}
	
	public void setBoardDef(String s)
	{
		cp.setBoardDef(s);
	}
	
	public void update(String s) {
		board = new Board();
		board.setFromString(s);
		if (solver != null) {
			solver.reset();
			solver.setBoard(board);
			solver.repaint();
		}
	}
	
	public void setSpeed(int s)
	{
		solver.setSpeed(s);
	}
	
	public void updateStatus (String s)
	{
		cp.updateStatus(s);
	}
	
	public void removeHighlight()
	{
		solver.removeHighlight();
		v.repaint();
	}
}
